<!--  -->
<script setup>
import { ref, reactive, toRefs, defineProps, onBeforeMount, onMounted, watchEffect, watch, computed } from 'vue' // eslint-disable-line
import { useStore } from 'vuex'
import { useRoute, useRouter } from 'vue-router'
import { generateTitle } from '@/utils/i18n'
/**
* 仓库
*/
const store = useStore() // eslint-disable-line
const linkHoverColor = ref(store.getters.cssVar.menuBg)
/**
* 路由对象
*/
const route = useRoute() // eslint-disable-line
// 生成数组解构
const breadcrumbData = ref([])
const getBreadcrumbData = () => {
  breadcrumbData.value = route.matched.filter(
    item => item.meta && item.meta.title
  )
}
watch(route, () => {
  getBreadcrumbData()
}, {
  immediate: true
})
/**
* 路由实例
*/
const router = useRouter() // eslint-disable-line
const onLinkClick = item => {
  router.push(item.path)
}
// 1-开始创建组件-setup
/**
* Props
*/
const props = defineProps({}) // eslint-disable-line
/**
* 数据部分
*/
const data = reactive({}) // eslint-disable-line
// 2.组件挂载页面之前执行----onBeforeMount
onBeforeMount(() => { })
// 3.-组件挂载到页面之后执行-------onMounted
onMounted(() => { })
watchEffect(() => { })
// 使用toRefs解构
// let { } = { ...toRefs(data) } // eslint-disable-line

</script>
<template>
  <el-breadcrumb class="breadcrumb" separator="/">
    <transition-group name="breadcrumb">
    <el-breadcrumb-item  v-for="(item, index) in breadcrumbData" :key="item.path">
      <!-- 不可点击 -->
      <span v-if="index === breadcrumbData.length  - 1" class="no-redirect">{{ generateTitle(item.meta.title) }}</span>
      <span v-else class="redirect" @click.prevent="onLinkClick(item)">{{ generateTitle(item.meta.title) }}</span>
    </el-breadcrumb-item>
  </transition-group>
  </el-breadcrumb>
</template>

<style scoped lang='scss'>
.breadcrumb {
  display: inline-block;
  font-size: 14px;
  line-height: 50px;
  margin-left: 8px;

  .redirect {
    color: #666;
    font-weight: 600;
    cursor: pointer;

    &:hover {
      // 将来需要进行主题替换，所以这里不去写死样式
      color: v-bind(linkHoverColor);
    }
  }

  ::v-deep .no-redirect {
    color: #97a8be;
    cursor: text;
  }
}
</style>
